package com.yc.cloud.admin.controller;

import com.yc.cloud.common.basic.api.ResponseResult;
import com.yc.cloud.common.orm.CommonPage;
import com.yc.cloud.admin.dto.request.AlarmRecordListParam;
import com.yc.cloud.common.basic.dto.BasePageReqDTO;
import com.yc.cloud.admin.dto.request.AlarmRecordCreateReqDTO;
import com.yc.cloud.admin.dto.request.AlarmRecordHandleReqDTO;
import com.yc.cloud.admin.dto.request.AlarmRecordUpdateReqDTO;
import com.yc.cloud.admin.vo.AlarmRecordVo;
import com.yc.cloud.admin.service.AlarmRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;

/**
 * <p>
 * 告警事件记录表 前端控制器
 * </p>
 *
 * @author kinggu
 * @since 2025-07-16
 */
@RestController
@Api(tags = "告警事件记录表")
@RequestMapping("/alarm-records")
public class AlarmRecordController {

    @Resource
    private AlarmRecordService alarmRecordService;

    @ApiOperation("创建告警事件记录表")
    @PostMapping
    public ResponseResult<Boolean> create(@Validated @RequestBody AlarmRecordCreateReqDTO createReqDTO) {
        return ResponseResult.success(alarmRecordService.create(createReqDTO));
    }

    @ApiOperation("更新告警事件记录表")
    @PutMapping("/{id}")
    public ResponseResult<Boolean> update(@PathVariable("id") Long id, @Validated @RequestBody AlarmRecordUpdateReqDTO updateReqDTO) {
        updateReqDTO.setId(id);
        return ResponseResult.success(alarmRecordService.update(updateReqDTO));
    }

    @ApiOperation("删除告警事件记录表")
    @DeleteMapping("/{id}")
    public ResponseResult<Boolean> delete(@PathVariable("id") Long id) {
        return ResponseResult.success(alarmRecordService.removeById(id));
    }

    @ApiOperation("获取告警事件记录表详情")
    @GetMapping("/{id}")
    public ResponseResult<AlarmRecordVo> getById(@PathVariable("id") Long id) {
        return ResponseResult.success(alarmRecordService.getVOById(id));
    }

    @ApiOperation("处理告警记录")
    @PutMapping("/{id}/handle")
    public ResponseResult<Boolean> handle(@PathVariable("id") Long id,
                                          @Validated @RequestBody AlarmRecordHandleReqDTO handleReqDTO) {
        return ResponseResult.success(alarmRecordService.handle(id, handleReqDTO));
    }

    @ApiOperation("分页查询告警事件记录表")
    @GetMapping
    public ResponseResult<CommonPage<AlarmRecordVo>> list(@Validated BasePageReqDTO pageReqDTO,
                                                          AlarmRecordListParam param) {
        return ResponseResult.success(alarmRecordService.list(pageReqDTO, param));
    }
}
